package cn.liyicun.cp.cpweb.base;

import java.io.Serializable;

public class Result<T> implements Serializable {

	private static final long serialVersionUID = 1L;

	private Integer status = 0;

	private String message = "";

	private T data = null;

	public Result(Integer status, String message) {
		this.status = status;
		this.message = message;

	}

	public Result(Integer status, String message, T data) {
		this.status = status;
		this.message = message;
		this.setData(data);
	}

	public static <T> Result<T> create(Integer status, String message, T data) {
		return new Result<>(status, message, data);
	}

	public static <T> Result<T> success(String message) {
		return new Result<>(200, message);
	}

	public static <T> Result<T> success() {
		return success("操作成功!");
	}

	public static <T> Result<T> successData(T data) {
		return create(200, "OK", data);
	}

	public static <T> Result<T> faildNoData() {
		return create(404, "nodata");
	}

	public static <T> Result<T> faildDataRepeat() {
		return create(404, "datarepeat");
	}

	public static <T> Result<T> create(Integer status, String message) {
		return new Result<T>(status, message);
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}
}
